package xcmg.device.web.warehouse;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.infra.AuthCode;
import xcmg.device.infra.BasicController;
import xcmg.device.service.vo.warehouse.MaterialTransferVO;
import xcmg.device.service.warehouse.MaterialTransferService;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.Arrays;

@RestController
@RequestMapping("/materialTransfer")
public class MaterialTransferController extends BasicController {
    @Autowired
    private MaterialTransferService materialTransferService;

    @RequestMapping(value = "/item",method = RequestMethod.GET)
    @ApiOperation(value = "查找单条记录详情")
    @FastMappingInfo(needLogin = true)
    public ActionResult item(String id)throws Exception{
        return actionValueResult(materialTransferService.findByPK(id, getOrgId()));
    }

    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation("查询移库记录列表")
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestBody SearchCommonVO<MaterialTransferVO> condition)throws Exception{
        MaterialTransferVO materialTransferVO =condition.getFilters();
        if(materialTransferVO == null){
            materialTransferVO = new MaterialTransferVO();
        }
        materialTransferVO.setOrgId(getOrgId());
        condition.setFilters(materialTransferVO);
        PageCommonVO pageCommonVO= materialTransferService.list(condition);
        return actionValueResult(pageCommonVO.getPageInfo());
    }

    @RequestMapping(value = "/export",method = RequestMethod.POST)
    @ApiOperation("导出区域调拨记录列表")
    @FastMappingInfo(needLogin = true)
    public void export(String[] ids)throws Exception {
        materialTransferService.export(Arrays.asList(ids));
    }

    @RequestMapping(value = "/exportAll",method = RequestMethod.POST)
    @ApiOperation("导出全部区域调拨记录列表")
    @FastMappingInfo(needLogin = true,code = AuthCode.MaterialTransfer.EXPORT)
    public void exportAll(MaterialTransferVO condition)throws Exception {
        condition.setOrgId(getOrgId());
        materialTransferService.exportAll(condition);
    }
}
